package com.huanletao.spring.lifecycle;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * <p>
 *
 * </p>
 *
 * @package: com.huanletao.spring.lifecycle
 * @Description:
 * @className: Main
 * @author: @NNCSKJ ADMIN
 * @copyright: Copyright (c) 2022/8/10 9:35
 * @version: V1.0
 */
public class Main {

    /*
     *  在使用上下文对象显示的调用start或stop方法时，会调用上下文中该接口的所有实现类的对应方法。
     */
    @Test
    public void lifecycleTest() {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
                "lifecycle.xml");
        // 必须显示调用
        classPathXmlApplicationContext.start();
        classPathXmlApplicationContext.stop();
    }

    @Test
    public void lifecycleTest2() {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
                "lifecycle.xml");
        // 模拟框架中的停止方法
      classPathXmlApplicationContext.stop();
    }
}
